﻿Friend Module MStringUtil
    Public Function StringEqualsSafe(ByVal strA_i As String, numIdxA_i As Int32, ByVal strB_i As String) As Boolean
        If strA_i.Length < numIdxA_i + strB_i.Length Then
            Return False
        End If

        Return strB_i = strA_i.Substring(numIdxA_i, strB_i.Length)
    End Function

    Public Function StringEqualsSafe(ByVal strA_i As String, numIdxA_i As Int32, ByVal strB_i As String, numLength_i As Int32) As Boolean
        Return StringEqualsSafe(strA_i, numIdxA_i, strB_i, 0, numLength_i)
    End Function

    Public Function StringEqualsSafe(ByVal strA_i As String, numIdxA_i As Int32, ByVal strB_i As String, numIdxB_i As Int32, numLength_i As Int32) As Boolean
        If strA_i.Length < numIdxA_i + numLength_i _
        OrElse strB_i.Length < numIdxB_i + numLength_i Then
            Return False
        End If

        Return strA_i.Substring(numIdxA_i, numLength_i) = strB_i.Substring(numIdxB_i, numLength_i)
    End Function


    Public Function StringEqualsSafe(ByVal strA_i As String, numIdxA_i As Int32, ByVal strB_i As String, ByVal enmComparisonType_i As StringComparison) As Boolean
        If strA_i.Length < numIdxA_i + strB_i.Length Then
            Return False
        End If

        Return strB_i.Equals(strA_i.Substring(numIdxA_i, strB_i.Length), enmComparisonType_i)
    End Function

    Public Function StringEqualsSafe(ByVal strA_i As String, numIdxA_i As Int32, ByVal strB_i As String, numLength_i As Int32, ByVal enmComparisonType_i As StringComparison) As Boolean
        Return StringEqualsSafe(strA_i, numIdxA_i, strB_i, 0, numLength_i, enmComparisonType_i)
    End Function

    Public Function StringEqualsSafe(ByVal strA_i As String, numIdxA_i As Int32, ByVal strB_i As String, numIdxB_i As Int32, numLength_i As Int32, ByVal enmComparisonType_i As StringComparison) As Boolean
        If strA_i.Length < numIdxA_i + numLength_i _
        OrElse strB_i.Length < numIdxB_i + numLength_i Then
            Return False
        End If

        Return String.Equals(strA_i.Substring(numIdxA_i, numLength_i), strB_i.Substring(numIdxB_i, numLength_i), enmComparisonType_i)
    End Function
End Module
